package view.main;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JOptionPane;

import model.initializeEntity.IntCompany;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import view.subwindosw.CompanyFrame;
import view.subwindosw.KeyInFrame;
import view.subwindosw.MedicineFrame;
import view.subwindosw.QueryFrame;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

public class Main {

	private JFrame frame;
	private static boolean company_windows = false;
	private static boolean medicine_windows = false;
	private static boolean keyin_windows = false;
	private static boolean Query_windows = false;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		final Logger logger = LoggerFactory.getLogger(Main.class);
		Main window = new Main();
		window.frame.setVisible(true);
	}

	/**
	 * Create the application.
	 */
	public Main() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		try {
			frame = new JFrame();
			frame.setTitle("算帳系統");
			frame.setResizable(false);
			frame.setBounds(100, 100, 264, 368);
			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			frame.setLocationRelativeTo(null);
			frame.getContentPane().setLayout(null);

			JButton ExitBt = new JButton("離開");
			ExitBt.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.exit(0);
				}
			});
			ExitBt.setFont(new Font("新細明體", Font.PLAIN, 20));
			ExitBt.setBounds(58, 248, 135, 35);
			frame.getContentPane().add(ExitBt);

			JButton BillBt = new JButton("新增帳單");
			BillBt.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if (!keyin_windows) {
						keyin_windows = true;
						KeyInFrame key;
						try {
							key = new KeyInFrame();
							key.setVisible(true);
						} catch (ClassNotFoundException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					} else {
						JOptionPane.showMessageDialog(null, "視窗已開啟");
					}
				}
			});
			BillBt.setFont(new Font("新細明體", Font.PLAIN, 20));
			BillBt.setBounds(58, 48, 135, 35);
			frame.getContentPane().add(BillBt);

			JButton button = new JButton("藥廠管理");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println(company_windows);
					if (!company_windows) {
						company_windows = true;
						CompanyFrame ComWindows;
						try {
							ComWindows = new CompanyFrame();
							ComWindows.setVisible(true);
						} catch (ClassNotFoundException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}

					} else {
						JOptionPane.showMessageDialog(null, "視窗已開啟");
					}
				}
			});
			button.setFont(new Font("新細明體", Font.PLAIN, 20));
			button.setBounds(58, 98, 135, 35);
			frame.getContentPane().add(button);

			JButton button_1 = new JButton("藥品管理");
			button_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					if (!medicine_windows) {
						MedicineFrame MeWindows;
						try {
							MeWindows = new MedicineFrame();
							MeWindows.setVisible(true);
							medicine_windows = true;
						} catch (ClassNotFoundException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}

					} else {
						JOptionPane.showMessageDialog(null, "視窗已開啟");
					}
				}
			});
			button_1.setFont(new Font("新細明體", Font.PLAIN, 20));
			button_1.setBounds(58, 148, 135, 35);
			frame.getContentPane().add(button_1);

			JButton button_2 = new JButton("帳單查詢");
			button_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if (!Query_windows) {
						new QueryFrame();
						Query_windows = true;
					} else {
						JOptionPane.showMessageDialog(null, "視窗已開啟");
					}
				}
			});
			button_2.setFont(new Font("新細明體", Font.PLAIN, 20));
			button_2.setBounds(58, 198, 135, 35);
			frame.getContentPane().add(button_2);
			new IntCompany().initialize();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static boolean isCompany_windows() {
		return company_windows;
	}

	public static void setCompany_windows(boolean company_windows) {
		Main.company_windows = company_windows;
	}

	public static boolean isMedicine_windows() {
		return medicine_windows;
	}

	public static void setMedicine_windows(boolean medicine_windows) {
		Main.medicine_windows = medicine_windows;
	}

	public static boolean isKeyin_windows() {
		return keyin_windows;
	}

	public static void setKeyin_windows(boolean keyin_windows) {
		Main.keyin_windows = keyin_windows;
	}

	public static boolean isQuery_windows() {
		return Query_windows;
	}

	public static void setQuery_windows(boolean query_windows) {
		Query_windows = query_windows;
	}

}
